package com.recruit.servlet;

import com.recruit.entity.Admin;
import com.recruit.service.AdminLoginService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/****
 * author:丁文彬
 * time：2020.9.26
 */
@WebServlet(name = "AdminLoginServlet",urlPatterns = "/adminLogin")
public class AdminLoginServlet extends HttpServlet {
    //service层
    private AdminLoginService adminLoginService = new AdminLoginService();



    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        Admin admin = adminLoginService.AdminLogin(username, password);
        if (admin!=null){

            //传送user对象到前端
            request.setAttribute("admin",admin);
            //主页
            request.getRequestDispatcher("adminMain.jsp").forward(request,response);
        }else {
            request.setAttribute("adminLoginMsg","用户名或密码不正确，请联系开发者！");
            request.getRequestDispatcher("admin.jsp").forward(request,response);
        }
    }
}
